<form id="TaskForm" action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card" data-table-id="TaskTable">
    <div class="layui-card-body">
        <div class="layui-form-item">
            <label class="layui-form-label label-required-next">发单人</label>
            <div class="layui-input-block">
                <select name='merchant_id' required class='layui-select' lay-search>
                    <option value=''>请选择发单人</option>
                    {foreach $merchant_list as $merchant}{eq name='$merchant.id' value='$vo.merchant_id|default=0'}
                    <option selected value='{$merchant.id}'>{$merchant.company|default=" - "} [{$merchant.nickname|default=" - "}]</option>
                    {else}
                    <option value='{$merchant.id}'>{$merchant.company|default=" - "} [{$merchant.nickname|default=" - "}]</option>
                    {/eq}{/foreach}
                </select>
                <p class="help-block"></p>
            </div>
        </div>

        <div class="layui-form-item"  style="display: none">
            <label class="layui-form-label label-required-next">订单任务分类</label>
            <div class="layui-input-block">
                <select name='category_id' required class='layui-select' lay-search>
                    <option value=''>请选择订单任务分类</option>
                    {foreach $category_list as $category}{eq name='$category.id' value='$vo.category_id|default=0'}
                    <option selected value='{$category.id}'>{$category.name}</option>
                    {else}
                    <option value='{$category.id}'>{$category.name}</option>
                    {/eq}{/foreach}
                </select>
                <p class="help-block"></p>
            </div>
        </div>

        <!--        <div class="layui-form-item">-->
        <!--            <label class="layui-form-label">订单任务名称</label>-->
        <!--            <div class="layui-input-block disabled">-->
        <!--                <input name="name" value='{$vo.name|default=""}'  required placeholder="请输入订单任务名称" class="layui-input">-->
        <!--                <p class="help-block"></p>-->
        <!--            </div>-->
        <!--        </div>-->


        <div class="layui-form-item transport-cate">
            <label class="layui-form-label label-required-next">货物种类</label>
            <div class="layui-input-block">
                <!--                <select name='transport_type' required class='layui-select' lay-search >-->
                <!--                    <option value=''>请选择货物种类</option>-->
                <!--                    {foreach :explode('；', sysconf('transport_type_list')) as $type}{eq name='$type' value='$vo.transport_type|default=""'}-->
                <!--                    <option selected value='{$type}'>{$type}</option>-->
                <!--                    {else}-->
                <!--                    <option value='{$type}'>{$type}</option>-->
                <!--                    {/eq}{/foreach}-->
                <!--                </select>-->
                {if $vo.transport_type == '其他'}
                <input name="transport_type" value='{$vo.transport_type|default="-"} [{$vo.transport_type_other|default="-"}]' required  class="layui-input">
                {else}
                <input name="transport_type" value='{$vo.transport_type|default="-"}' required  class="layui-input">
                {/if}
                <p class="help-block"></p>
            </div>
        </div>

        <div class="layui-form-item transport-cate">
            <label class="layui-form-label label-required-next">运输场景</label>
            <div class="layui-input-block">
                <!--                <select name='transport_scene' required class='layui-select' lay-search >-->
                <!--                    <option value=''>请选择运输场景</option>-->
                <!--                    {foreach :explode('；', sysconf('transport_scene_list')) as $scene}{eq name='$scene' value='$vo.transport_scene|default=""'}-->
                <!--                    <option selected value='{$scene}'>{$scene}</option>-->
                <!--                    {else}-->
                <!--                    <option value='{$scene}'>{$scene}</option>-->
                <!--                    {/eq}{/foreach}-->
                <!--                </select>-->
                {if $vo.transport_scene == '其他'}
                <input name="transport_scene" value='{$vo.transport_scene|default="-"} [{$vo.transport_scene_other|default="-"}]' required  class="layui-input">
                {else}
                <input name="transport_scene" value='{$vo.transport_scene|default="-"}' required  class="layui-input">
                {/if}
                <p class="help-block"></p>
            </div>
        </div>

        <div class="layui-form-item transport-cate">
            <label class="layui-form-label label-required-next">订单距离</label>
            <div class="layui-input-block">
                <!--                <select name='transport_distance' required class='layui-select' lay-search >-->
                <!--                    <option value=''>请选择订单距离</option>-->
                <!--                    {foreach :explode('；', sysconf('transport_distance_list')) as $distance}{eq name='$distance' value='$vo.transport_distance|default=""'}-->
                <!--                    <option selected value='{$distance}'>{$distance}</option>-->
                <!--                    {else}-->
                <!--                    <option value='{$distance}'>{$distance}</option>-->
                <!--                    {/eq}{/foreach}-->
                <!--                </select>-->
                <input name="transport_distance" value='{$vo.transport_distance|default=""}' required  class="layui-input">
                <p class="help-block"></p>
            </div>
        </div>

        <div class="layui-form-item transport-cate">
            <label class="layui-form-label">货物重量</label>
            <div class="layui-input-block">
                <input name="weight" value='{$vo.weight|default=""}' required placeholder="请输入货物重量" class="layui-input">
                <p class="help-block">单位：吨</p>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">任务时间</label>
            <div class="layui-input-block">
                <input id="exectime" name="exec_at" value='{$vo.exec_at|default=""}' required placeholder="请选择订单任务时间" class="layui-input">
                <p class="help-block"></p>
            </div>
        </div>

        <!--        <div class="layui-form-item transport-cate">-->
        <!--            <label class="layui-form-label">开始时间</label>-->
        <!--            <div class="layui-input-block">-->
        <!--                <input id="starttime" name="start_at" value='{$vo.start_at|default=""}' required placeholder="请选择开始时间" class="layui-input">-->
        <!--                <p class="help-block"></p>-->
        <!--            </div>-->
        <!--        </div>-->

        <!--        <div class="layui-form-item transport-cate">-->
        <!--            <label class="layui-form-label">结束时间</label>-->
        <!--            <div class="layui-input-block">-->
        <!--                <input id="endtime" name="end_at" value='{$vo.end_at|default=""}' required placeholder="请选择结束时间" class="layui-input">-->
        <!--                <p class="help-block"></p>-->
        <!--            </div>-->
        <!--        </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">任务地点</label>
            <div class="layui-input-block ">
                <input  name="place" value='{$vo.place|default=""}' required placeholder="请输入订单任务地点" class="layui-input">
                <p class="help-block"></p>
            </div>
        </div>

        <!--        <div class="layui-form-item transport-cate">-->
        <!--            <label class="layui-form-label">起飞地点</label>-->
        <!--            <div class="layui-input-block ">-->
        <!--                <input  name="place" value='{$vo.place|default=""}' required placeholder="请输入订单任务地点" class="layui-input">-->
        <!--                <p class="help-block"></p>-->
        <!--            </div>-->
        <!--        </div>-->

        <!--        <div class="layui-form-item transport-cate">-->
        <!--            <label class="layui-form-label">到达地点</label>-->
        <!--            <div class="layui-input-block ">-->
        <!--                <input  name="place2" value='{$vo.place2|default=""}' required placeholder="请输入订单任务地点" class="layui-input">-->
        <!--                <p class="help-block"></p>-->
        <!--            </div>-->
        <!--        </div>-->


        <div class="layui-form-item">
            <label class="layui-form-label">预估价格</label>
            <div class="layui-input-block">
                <input name="money" value='{$vo.money|default=""}' required placeholder="请输入订单任务报酬" class="layui-input">
                <p class="help-block">单位：元</p>
            </div>
        </div>

        <!--        <div class="layui-form-item">-->
        <!--            <label class="layui-form-label">订单订单描述</label>-->
        <!--            <div class="layui-input-block">-->
        <!--                <textarea name="desc" required placeholder="请输入订单任务描述" class="layui-textarea">{$vo.desc|default=""}</textarea>-->
        <!--                <p class="help-block"></p>-->
        <!--            </div>-->
        <!--        </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">订单要求</label>
            <div class="layui-input-block">
                <textarea name="require" required placeholder="请输入订单任务要求" class="layui-textarea">{$vo.require|default=""}</textarea>
                <p class="help-block"></p>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">审批文件</label>
            <div class="layui-input-block">
                <a class="layui-btn layui-btn-sm layui-btn-normal" href="{$vo.file|default=''}" target="_blank">下载文件</a>
                <p class="help-block"></p>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label label-required">审核结果</label>
            <div class="layui-input-block ">
                <div class="layui-input border-0">
                    <input type="radio" name="gov_review_status" value="1" title="通过" checked>
                    <input type="radio" name="gov_review_status" value="-1" title="驳回" >
                </div>
                <p class="help-block"></p>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">审核意见</label>
            <div class="layui-input-block">
                <textarea name="review_reason" placeholder="请输入审核意见" class="layui-textarea">{$vo.review_reason|default=""}</textarea>
                <p class="help-block"></p>
            </div>
        </div>
    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>
</form>

<script>
    // 时间选择器
    laydate.render({elem: '#exectime', type: 'datetime'});
    layui.use('form', function(){
        var form = layui.form;
        // 选择表单元素
        var formElement = document.getElementById('TaskForm');
        var formElements = formElement.querySelectorAll('input, select, textarea');
        // 排除指定元素
        formElements = Array.from(formElements).filter(el => !['id', 'gov_review_status', 'review_reason'].includes(el.getAttribute('name')));
        // 遍历这些元素并禁用它们
        formElements.forEach(function(el) {
            el.disabled = true;
            el.classList.add('layui-disabled');
        });
        // 如果需要动态更新Layui样式，可以重新渲染表单
        form.render();


        // 显示隐藏默认值
        function toggleTransportCate(categoryId) {
            const isTransport = categoryId == 1;
            $(".transport-cate").toggle(isTransport);
            $(".no-transport-cate").toggle(!isTransport);
        }
        // 监听分类修改
        form.on('select(category_id)', function(data){
            toggleTransportCate(data.value);
        });
        // 初始化时执行一次
        toggleTransportCate($('#TaskForm [name=category_id]').val());
    });
</script>